<template>
	<el-header style="height: auto;">
		<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
	</el-header>
	<el-header>
		<div class="left-panel">
			<el-button-group>
			</el-button-group>
		</div>
		<div class="right-panel">
			<div class="right-panel-search">
				<el-input v-model="search.keyword" placeholder="收文标题" clearable></el-input>
				<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
			</div>
		</div>
	</el-header>
	<el-main class="nopadding">
		<scTable ref="table" :params="{model:'1',isDoc:'2'}" :apiObj="list.apiObj" row-key="runId" stripe remoteSort remoteFilter>
			<el-table-column label="流水号" prop="id" width="100" align="center"></el-table-column>
			<el-table-column label="收文标题" prop="flowTitle" width="400" :show-overflow-tooltip="true"></el-table-column>
			<el-table-column label="流程名称" prop="flowName" width="300" :show-overflow-tooltip="true"></el-table-column>
			<el-table-column label="紧急程度" prop="urgency" width="100" align="center">
				<template #default="scope">
					<el-tag v-if="scope.row.urgency==0" type="success">一般</el-tag>
					<el-tag v-else-if="scope.row.urgency==1" type="warning">紧急</el-tag>
					<el-tag v-else-if="scope.row.urgency==2" type="danger">加急</el-tag>
					<el-tag v-else type="info">未知</el-tag>
				</template>
			</el-table-column>
			<el-table-column label="流程类型" prop="flowType" width="100">
				<template #default="scope">
					<el-tag type="success" v-if="scope.row.flowType==0" effect="dark">常规</el-tag>
					<el-tag v-else-if="scope.row.flowType==1" effect="dark">灵活</el-tag>
					<el-tag type="warning" v-else-if="scope.row.flowType==2" effect="dark">顺序</el-tag>
					<el-tag type="danger" v-else-if="scope.row.flowType==3" effect="dark">预设</el-tag>
					<el-tag type="info" v-else effect="dark">未知</el-tag>
				</template>
			</el-table-column>
			<el-table-column label="创建时间" prop="createTime" width="150" align="center">
				<template #default="scope">
					<el-tag v-time="scope.row.createTime" format="yyyy-MM-dd hh:mm"></el-tag>
				</template>
			</el-table-column>
			<el-table-column label="操作" fixed="right" align="right" width="170">
				<template #default="scope">
					<el-button-group>
						<el-button text type="primary" size="small" @click="readBpmDetails(scope.row,scope.$index)">查看</el-button>
						<el-button text type="primary" size="small" @click="handleBpm(scope.row, scope.$index)">办理</el-button>
						<el-popconfirm title="确定删除吗？" @confirm="deleteLogicBpm(scope.row, scope.$index)">
							<template #reference>
								<el-button text type="primary" size="small">删除</el-button>
							</template>
						</el-popconfirm>
					</el-button-group>
				</template>
			</el-table-column>
		</scTable>
	</el-main>
</template>
<script>
import scSelectFilter from '@/components/scSelectFilter'
export default {
	name: 'Bpm Drafts',
	components: {
		scSelectFilter,
	},
	data() {
		return {
			filterData: [
				{
					title: "日期范围",
					key: "date",
					multiple: false,
					options: [
						{
							label: "全部",
							value: ""
						},
						{
							label: "今日",
							value: "1"
						},
						{
							label: "昨日",
							value: "2"
						},
						{
							label: "一周内",
							value: "3"
						},
						{
							label: "一月内",
							value: "4"
						},
						{
							label: "一月前",
							value: "5"
						}
					]
				},
				{
					title: "收文分类",
					key: "flowId",
					multiple: true,
					options: [{
						label: "全部",
						value: ""
					}]
				}
			],
			list: {
				apiObj: this.$API.bpm.bpmList.getDraftsBpmFlowList
			},
			search: {
				model:'1',
				isDoc:'2',
				date:'',
				flowId:'',
				keyword: ""
			}
		}
	},
	mounted() {
		this.getDraftsBpmFlowListFilter();
	},
	methods: {
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
		filterChange(data) {
			this.search.date = data.date;
			this.search.flowId = data.flowId;
			this.$refs.table.upData(this.search)
		},
		async getDraftsBpmFlowListFilter() {
			var res = await this.$API.bpm.bpmFlow.getDraftsBpmFlowListFilter.get({model:'1',isDoc:'2'});
			if (res.code == 200) {
				this.filterData[1].options = res.data
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		async deleteLogicBpm(row,index)
		{
			var res = await this.$API.bpm.bpmList.deleteLogicBpm.post({runId:row.runId});
			if (res.code == 200) {
				this.$message.success("操作成功");
				this.$refs.table.refresh();
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		handleBpm(row,index)
		{
			this.$nextTick(() => {
				this.$router.replace({
					path: '/doc/handle/dowork',
					query:{
						runId:row.runId,
						stepRunId:row.stepRunId,
						flowId:row.flowId
					}
				})
			})
		},
		readBpmDetails(row,index)
		{
			this.$nextTick(() => {
				this.$router.replace({
					path: '/doc/handle/read',
					query: {
						runId: row.runId
					}
				})
			})
		},
	}
}
</script>
